home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.004.Custom.Control / BoxCtrl.Stds.aii < prev    next >
Encoding:
Text File  |  1990-04-17  |  7.7 KB  |  379 lines  |  [TEXT/MPS ]

  1.     PRINT PUSH,OFF
  2.  
  3.     EJECT
  4. *******************************************************************************
  5. *
  6. InitTools    PROC
  7. *
  8. * Description:    Load and initialize the tools needed. Errors are detected
  9. *    and FatalError is called if any occur. If there aren't any
  10. *    errors, the list of menu templates is read and the menu-
  11. *    bar is created.
  12. *
  13. *
  14. * Inputs:    NONE
  15. *
  16. * Outputs:    NONE
  17. *
  18. * External Refs:
  19.     import FatalError
  20. *
  21. * Entry Points:    NONE
  22. *
  23. *******************************************************************************
  24.     with Globals
  25.  
  26. ;
  27. ;   Tool Direct page offsets here
  28. ;
  29. QDDPage    equ $0000
  30. EMDPage    equ QDDPage+$0300
  31. CtlDPage    equ EMDPage+$0100
  32. MenuDPage    equ CtlDPage+$0100
  33. LEDPage    equ MenuDPage+$0100
  34. ToolDPSize    equ LEDPage+$0100
  35.  
  36.     phk    ; Save program bank register and
  37.     plb    ; load it as the data bank register
  38.  
  39.     tdc
  40.     sta MyDP    ; Save direct register
  41.  
  42.     _TLStartup    ; Start Tool Locator
  43.  
  44.     pha    ; Space for result
  45.     _MMStartup    ; Start memory manager
  46.     PullWord MyID    ; Save it for later use
  47.  
  48.     _MTStartup    ; Start up Misc Tools
  49.  
  50.     _IMStartup    ; Start integer math toolset
  51.  
  52.     PushLong #ToolTable    ; Pointer to Tool table
  53.     _LoadTools    ; Load all RAM based tools
  54.     bcc IT0005    ; Carry clear means no error
  55.     brl FatalError    ; Tools can't be loaded. Fatal error!
  56.  
  57. IT0005
  58.  
  59. ; Get memory for Tool Direct pages
  60.  
  61.     pha    ; Room for result
  62.     pha
  63.     PushLong #ToolDPSize; Number of bytes needed
  64.     PushWord MyID    ; ID of this application
  65.     PushWord #attrLocked+attrFixed+attrPage+attrBank
  66.     PushLong #0    ; Allocate them in bank 0
  67.     _NewHandle
  68.     bcc IT0010    ; Test carry for error
  69.     brl FatalError    ; If no memory we got a fatal error!
  70.  
  71. IT0010    PullLong DPHandle    ; Retrieve handle to our DPage area
  72.  
  73.     lda [DPHandle]    ; Dereference the handle to get a ptr
  74.     sta DPPointer    ; to our direct page area and save it.
  75.  
  76.     PushWord DPPointer    ; QuickDraw uses 3 pages of Dpage
  77.     PushWord #ScreenMode; Used to set all master SCB's
  78.     PushWord #0    ; Zero means use default buf size
  79.     PushWord MyID    ; Application ID for allocating data
  80.     _QDStartup    ; Start QuickDraw, turn on SHR Screen
  81.     bcc IT0015
  82.     brl FatalError    ; If it can't be started then bomb
  83.  
  84. IT0015
  85.     lda DPPointer    ; Create address for Event Mgr DPage by
  86.     clc    ; loading in the pointer to the start
  87.     adc #EMDPage    ; of DPage and adding Evt Mgr offset.
  88.     pha    ; Now push it on the stack.
  89.     PushWord #20    ; Size of event queue.
  90.     PushWord #0    ; MouseClamp values.
  91.     PushWord #ScreenWidth ; These will clamp mouse to screen
  92.     PushWord #0    ; area only.
  93.     PushWord #200
  94.     PushWord MyID
  95.     _EMStartup    ; Start the event manager
  96.     bcc IT0020
  97.     brl FatalError    ; Event manager is also a must
  98. IT0020
  99.     PushWord MyID
  100.     _WindStartup
  101.     bcc IT0025
  102.     brl FatalError
  103. IT0025
  104.     PushWord MyID
  105.     lda DPPointer
  106.     clc
  107.     adc #CtlDPage
  108.     pha
  109.     _CtlStartup
  110.     bcc IT0030
  111.     brl FatalError
  112. IT0030
  113.  
  114.     PushWord MyID
  115.     lda DPPointer
  116.     clc
  117.     adc #MenuDPage
  118.     pha
  119.     _MenuStartUp
  120.     bcc IT0035
  121.     brl FatalError
  122. IT0035
  123.     PushWord MyID
  124.     lda DPPointer
  125.     clc
  126.     adc #LEDPage
  127.     pha
  128.     _LEStartUp
  129.     bcc IT0040
  130.     brl FatalError
  131. IT0040
  132.     PushWord MyID
  133.     _DialogStartup
  134.     bcc IT0045
  135.     brl FatalError
  136. IT0045
  137.     _ScrapStartup    ; No errors possible for this call
  138.  
  139.     _DeskStartup    ; No error possible for this call
  140.  
  141. ; insert application specific tools here
  142.  
  143.     PushLong #0
  144.     _RefreshDeskTop
  145.  
  146. ;
  147. ; Create the menus I need
  148. ;
  149.  
  150.     ldx #MenuPtrLen-4    ; Get a pointer to the last menu    
  151. loop    phx    ; Save menu table index on the stack
  152.     pha    ; Push on space for the menu handle
  153.     pha    ;   returned by NewMenu
  154.     lda MenuPtr+2,x    ; Push on the pointer to the template
  155.     pha    ;   to be used by NewMenu when
  156.     lda MenuPtr,x    ;   creating the menu
  157.     pha
  158.     _NewMenu    ; Create a new menu
  159.     PushWord #0    ; Tell InsertMenu where to put it
  160.     _InsertMenu    ; Insert it.
  161.     plx    ; Get our index back off the stack
  162.     dex    ; Point to the next template pointer
  163.     dex
  164.     dex
  165.     dex
  166.     bpl loop    ; Go back up if not done yet.
  167.  
  168.     PushWord #1    ; Add NDA's
  169.     _FixAppleMenu
  170.  
  171.     pha    ; Now call CalcMenuSize for all menus
  172.     _FixMenuBar
  173.     PullWord MenuHeight
  174.  
  175.     _DrawMenuBar    ; Finally, draw it.
  176.  
  177.     RTS
  178.  
  179. ToolTable    dc.W 6    ; Data Block for LoadTools call
  180.     dc.W 14,$0100    ; Window Manager
  181.     dc.W 15,$0100    ; Menu Manager
  182.     dc.W 16,$0100    ; Control Manager
  183.     dc.W 20,$0100    ; LineEdit tool set
  184.     dc.W 21,$0100    ; Dialog Manager
  185.     dc.W 22,$0100    ; Scrap manager
  186.  
  187.     ENDP
  188.  
  189.     EJECT
  190. *******************************************************************************
  191. *
  192. FatalError    PROC
  193. *
  194. * Description:    Routine that is called whenever a tool sends back an error
  195. *    that can not be recovered from. This routine prints the
  196. *    error on the screen, waits for a keypress then quits back
  197. *    to whoever started this application up!
  198. *
  199. *
  200. * Inputs:    A = Error number
  201. *
  202. * Outputs:    NONE (program exits)
  203. *
  204. * External Refs:
  205.     import CloseTools
  206. *
  207. * Entry Points:    NONE
  208. *
  209. *******************************************************************************
  210.     with Globals
  211.  
  212.     pha    ; Push the error code
  213.     PushLong #ErrNumStr    ; Address of storage area
  214.     PushWord #4    ; Length of string
  215.     _Int2Hex
  216.  
  217.     _GrafOff    ; If QD Started, shut off graphics
  218.  
  219.     PushLong #ErrStr    ; Write error message to the screen
  220.     _WriteCString
  221.  
  222.     pha    ; Space for result
  223.     PushWord #0    ; No echo
  224.     _ReadChar    ; Wait for a key to be pressed
  225.     pla    ; Discard the key
  226.  
  227.     jsr CloseTools    ; Shut down all the tools in case
  228. ;          any got started up
  229.  
  230.     _Quit QuitParms    ; Quit back to where we came from.
  231.  
  232.     brk $FF    ; If the quit fails then just break
  233.     
  234. ErrStr    dc.B 'A fatal error has occured $'
  235. ErrNumStr    dc.B 'xxxx   press any key to exit',0
  236.  
  237.     ENDP
  238.  
  239.     EJECT
  240. *******************************************************************************
  241. *
  242. CloseTools    PROC
  243. *
  244. * Description:    Shut down the tools I started.
  245. *
  246. *
  247. * Inputs:    NONE
  248. *
  249. * Outputs:    NONE
  250. *
  251. * External Refs:    NONE
  252. *
  253. * Entry Points:    NONE
  254. *
  255. *******************************************************************************
  256.     with Globals
  257.  
  258.     _DeskShutDown
  259.     _ScrapShutDown
  260.     _DialogShutDown
  261.     _LEShutDown
  262.     _MenuShutDown
  263.     _CtlShutDown
  264.     _WindShutDown
  265.     _EMShutDown
  266.     _QDShutDown
  267.     _MTShutDown
  268.  
  269.     PushLong DPHandle    ; Dispose of all that DP memory
  270.     _DisposeHandle
  271.  
  272.     PushWord MyID
  273.     _MMShutDown
  274.     _TLShutDown
  275.  
  276.     rts
  277.     ENDP
  278.  
  279.     EJECT
  280. *******************************************************************************
  281. *
  282. doAbout    PROC
  283. *
  284. * Description:    Bring up an Alert Dialog box with our name in it.
  285. *
  286. * Inputs:    NONE
  287. *
  288. * Outputs:    NONE
  289. *
  290. * External Refs:    NONE
  291. *
  292. * Entry Points:    NONE
  293. *
  294. *******************************************************************************
  295.     With Globals
  296.  
  297.     pha    ; space for result
  298.     PushLong #AboutBox    ; pointer to alert template
  299.     PushLong #0    ; pointer to a filter proc (0=none)
  300.     _NoteAlert
  301.     pla    ; get the item hit and dispose
  302.  
  303.     rts
  304.  
  305. ; About Box alert template
  306.  
  307. AboutBox    dc.W 30,30,100,590    ; for 320 use 30,30,100,290
  308.     dc.W 1    ; this is alert # 1
  309.     dc.B $80    ; draw for this stage
  310.     dc.B $81    ; draw for this stage
  311.     dc.B $82    ; draw for this stage
  312.     dc.B $83    ; draw for this stage
  313.     dc.L OKButton    ; ok button for the    alert
  314.     dc.L AboutTitle    ; title of the program
  315.     dc.L AboutAut    ; author
  316.     dc.L AboutVers    ; version number string
  317.     dc.L 0    ; nil to end the list
  318.  
  319. OKBTitle    dc.B 2,'OK'
  320. OKButton    dc.W 1
  321.     dc.W 50,500,65,550
  322.     dc.W buttonItem
  323.     dc.L OKBTitle
  324.     dc.W 0
  325.     dc.W 0    ; item flag
  326.     dc.L 0    ; no color table
  327.  
  328. AboutTitle    dc.W 2
  329.     dc.W 10,100,20,550
  330.     dc.W statText+itemDisable
  331.     dc.L TitleString
  332.     dc.W 0
  333.     dc.W 0    ; item flag
  334.     dc.L 0    ; no color table
  335.  
  336. AboutAut    dc.W 3
  337.     dc.W 25,100,35,550
  338.     dc.W statText+itemDisable
  339.     dc.L AutString
  340.     dc.W 0
  341.     dc.W 0    ; item flag
  342.     dc.L 0    ; no color table
  343.  
  344. AboutVers    dc.W 4
  345.     dc.W 40,100,50,550
  346.     dc.W statText+itemDisable
  347.     dc.L VersString
  348.     dc.W 0
  349.     dc.W 0    ; item flag
  350.     dc.L 0    ; no color table
  351.  
  352.     ENDP
  353.  
  354.     EJECT
  355. *******************************************************************************
  356. *
  357. doQuit    PROC
  358. *
  359. * Description:    Quit routine. Set the QuitFlag to TRUE for the EventLoop.
  360. *
  361. *
  362. * Inputs:    NONE
  363. *
  364. * Outputs:    QuitFlag set to $FFFF
  365. *
  366. * External Refs:    NONE
  367. *
  368. * Entry Points:    NONE
  369. *
  370. *******************************************************************************
  371.     With Globals
  372.  
  373.     lda #$FFFF
  374.     sta QuitFlag
  375.     rts
  376.     ENDP
  377.  
  378.     PRINT POP
  379.